<?php
namespace app\common\logic\ad\driver;


use app\common\logic\ad\Driver;
use app\common\model\ad\Ads;
use think\Db;
use think\Exception;
use think\exception\ValidateException;

/**
 * Created by PhpStorm.
 * User: yangchunfu
 * Date: 2019/12/24
 * Time: 4:36 PM
 */

class Start extends Driver
{
    protected $options = [
    ];
    //1代表开机广告
    protected $rule = [1];

    protected $htmlTpl = 'start.html';
    protected $ruleWhere = [
        'mark' => 'start'
    ];



    public function insertRule($ads_id = null)
    {
        $select = 0;
        if ($ads_id) {
            $ad = Ads::get($ads_id);
            $select = $ad->type;
        }
        $select_string = build_select('row[type]', ['0'=> '图片', '1' => '视频'], $select,[
            'class'=>'form-control',
            'data-rule'=>'required'
        ]);
        $html = <<<EOD
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">请选择广告类型:</label>
        <div class="col-xs-12 col-sm-8">
            {$select_string}               
        </div>
    </div>
EOD;

        return $html;
    }


    /**********************************接口部分*/

    /**
     * 获取广告 接口 api
     * @return array
     */
    public function select($where = []){

        //获取广告数据
        $ad = $this->adModel->where('id','IN',function($query) use($where) {
            $query->name('self_ad_rule')->where($this->getRule())->field('ad_ads_id');
        })->find();

        return $ad;
    }

}